from http.server import HTTPServer, SimpleHTTPRequestHandler
import sys

class CORSRequestHandler(SimpleHTTPRequestHandler):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.extensions_map = {
            '': 'application/octet-stream',
            '.html': 'text/html',
            '.js': 'application/javascript',
            '.css': 'text/css',
        }

    def end_headers(self):
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
        self.send_header('Access-Control-Allow-Headers', 'Content-Type, Authorization')
        super().end_headers()

    def do_OPTIONS(self):
        self.send_response(200)
        self.end_headers()

port = 8000
print(f"Starting server at http://localhost:{port}")
print("Press Ctrl+C to stop the server")
httpd = HTTPServer(('localhost', port), CORSRequestHandler)
httpd.serve_forever()
